//1、实现对圆形、三角形、长方形求面积
package main

import (
    "fmt"
)

type Areaer interface {
    area(float64, float64) float64
}

type Circle struct {
    Pi float64
    Radial  float64
}

func (*Circle) area(pi,r float64) float64 {
    return pi*r*r
}

type Triangle struct {
    bottom,high float64
}

func (*Triangle) area(b,h float64) float64 {
    return b*h/2
}

type Rectangle struct {
    length,wide float64
}

func (*Rectangle) area(l,w float64) float64 {
    return l*w
}

func garea(a Areaer,x float64,y float64) {
    a.area(x,y)
}

//在接口之上封装普通函数,接口为参数,因为这三种图形结构体都实现了接口,因此都满足该接口,调用接口参数的方法,即是调用对应结构体实例的方法,实现了多态

func main() {
    c := new(Circle)
    c.Pi = 3.14
    c.Radial = 10
    fmt.Printf("圆形面积为: %v\n",c.area(c.Pi,c.Radial))
    t :=new(Triangle)
    t.bottom = 10
    t.high = 5.5
    fmt.Printf("三角形面积为: %v\n", t.area(t.bottom,t.high))
    r :=new(Rectangle)
    r.length = 15.3
    r.wide = 9.9
    fmt.Printf("矩形面积为: %v\n", t.area(r.length,r.wide))

}


